package com.work.xxzl.module.pagehome;

import android.os.Bundle;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.TypedValue;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.work.xxzl.R;
import com.work.xxzl.adapter.CommonRecyclerViewAdapter;
import com.work.xxzl.adapter.CommonRecyclerViewHolder;
import com.work.xxzl.base.BaseFragment;
import com.work.xxzl.utils.UIUtils;
import com.work.xxzl.view.SpaceItemDecoration;
import com.work.xxzl.view.SwipRefreshViewCommon;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * author: Aly
 * date :2018/12/7 16:27
 * version:1.0
 * description:征婚
 */
public class MatrimoniaFragment extends BaseFragment {
    @BindView(R.id.recycleview)
    RecyclerView recycleview;
    @BindView(R.id.swiprefreshview)
    SwipRefreshViewCommon swiprefreshview;
    private List<String> mDatas = new ArrayList<>();
    private CommonRecyclerViewAdapter<String> adapter;
    private int key;

    @Override
    protected int getLayoutId() {
        return R.layout.layout_recycleview;
    }

    @Override
    protected void initView() {
        Bundle bundle = getArguments();
        if (bundle != null) {
            key = bundle.getInt("key");
        }
        setAdapter();
    }


    @Override
    protected void initData() {
        super.initData();
        setRefresh();
    }

    private void setRefresh() {
        swiprefreshview.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                swiprefreshview.setRefreshing(false);
            }
        });
    }

    //设置适配器
    private void setAdapter() {
        for (int i = 0; i < 10; i++) {
            mDatas.add("");
        }
        adapter = new CommonRecyclerViewAdapter<String>(getContext(), mDatas) {
            private RelativeLayout rt_look, rt_love;
            private ImageView iv_image,iv_level;
            private TextView tv_nickname, tv_old, tv_jiaoyou, tv_zhenghun;
            private LinearLayout lt_daoshi;
            private TextView tv_distance;

            @Override
            public void convert(CommonRecyclerViewHolder holder, String entity, int position) {


                tv_distance = holder.getView(R.id.tv_distance);
                if(key==1){
                    tv_distance.setVisibility(View.VISIBLE);
                }

                iv_level = holder.getView(R.id.iv_level);
                tv_jiaoyou = holder.getView(R.id.tv_jiaoyou);
                tv_zhenghun = holder.getView(R.id.tv_zhenghun);
                lt_daoshi = holder.getView(R.id.lt_daoshi);
                rt_look = holder.getView(R.id.rt_look);
                rt_love = holder.getView(R.id.rt_love);
                tv_nickname = holder.getView(R.id.tv_nickname);
                tv_old = holder.getView(R.id.tv_old);
                rt_look.setVisibility(View.GONE);
                rt_love.setVisibility(View.GONE);
                iv_image = holder.getView(R.id.iv_image);
                tv_old.setPadding(5, 0, 8, 0);
                ViewGroup.LayoutParams layoutParams = iv_image.getLayoutParams();
                layoutParams.height = (UIUtils.getScreenWidth() - UIUtils.dip2px(15)) / 2 * 4 / 3;
                layoutParams.width = UIUtils.getScreenWidth() / 2;
                iv_image.setLayoutParams(layoutParams);
                //征婚会员
                tv_jiaoyou.setVisibility(View.GONE);
                tv_zhenghun.setVisibility(View.VISIBLE);
                lt_daoshi.setVisibility(View.GONE);
                iv_level.setImageResource(R.mipmap.zuanshi);
                tv_old.setText("未婚");
                tv_old.setBackgroundResource(R.drawable.bghalfred_oval);
                tv_old.setCompoundDrawables(null, null, null, null);
                holder.setImage(R.id.iv_image, "http://pic44.nipic.com/20140719/7798805_152213709841_2.jpg");
            }

            @Override
            public int getLayoutViewId(int viewType) {
                return R.layout.item_homepage_suggestfragment;
            }
        };
        recycleview.setPadding(UIUtils.dip2px(3), 0, UIUtils.dip2px(3), 0);
        recycleview.setLayoutManager(new GridLayoutManager(getContext(), 2));
        recycleview.addItemDecoration(new SpaceItemDecoration(UIUtils.dip2px(2)));
        recycleview.setAdapter(adapter);
    }
}
